/*
 * Copyright 2018 peipeihh
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * limitations under the License.
 */
package com.pphh.demo.remote;

import com.pphh.demo.job.HelloJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * RemoteSchedulerClient
 *
 * @author huangyinhuang
 * @date 6/5/2018
 */
public class RemoteSchedulerClient {
    private static Logger log = LoggerFactory.getLogger(RemoteSchedulerClient.class);

    public static void main(String[] args) throws SchedulerException {
        RemoteSchedulerClient remoteClient = new RemoteSchedulerClient();
        remoteClient.run();
    }

    public void run() throws SchedulerException {
        JobDetail job = JobBuilder.newJob(HelloJob.class)
                .withIdentity("MyJob", "MyGroup")
                .build();

        CronTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("MyTrigger", "MyGroup")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
                .build();

        log.info("start the scheduler.");
        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
        scheduler.scheduleJob(job, trigger);
    }
}
